package cn.yunhe.spring.mybatis.service.impl;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.yunhe.spring.mybatis.dao.UserMapper;
import cn.yunhe.spring.mybatis.model.Page;
import cn.yunhe.spring.mybatis.model.User;
import cn.yunhe.spring.mybatis.service.IUserService;

@Service("userService")
public class UserServiceImpl implements IUserService{
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User getUser(User user){
		return userMapper.getUser(user);
	}

	@Override
	public void addUser(User user) {
		userMapper.addUser(user);
	}

	@Override
	public void delUser(User user) {
		userMapper.delUser(user);
	}

	@Override
	public void editUser(User user) {
		userMapper.editUser(user);		
	}

	@Override
	public Page queryLikeUser(Map<String, Object> cond) {
		Page page=new Page();
		page.setTotalNum(userMapper.getLikeUserCount(cond));
		int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
		int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(userMapper.getLikeUser(cond));
		return page;
	}
	
}
